//
//  YCWelecomView.swift
//  WeiboDemo
//
//  Created by 尹成 on 2017/1/18.
//  Copyright © 2017年 yc. All rights reserved.
//

import UIKit
import SDWebImage

class YCWelecomView: UIView {
    
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var nickNameLb: UILabel!
    @IBOutlet weak var bottomConst: NSLayoutConstraint!
    
    class func loadFromXib() -> YCWelecomView {
        let nib = UINib.init(nibName: "YCWelecomView", bundle: nil)
        let vc = nib.instantiate(withOwner: self, options: [:])[0] as? YCWelecomView
        
        vc?.frame = UIScreen.main.bounds
        return vc!
    }
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        //        layer.masksToBounds;
        //        layer.cornerRadius
        let urlString = YCNetworkManager.shared.userAccount.avatar_large ?? ""
        iconView .sd_setImage(with: URL(string:urlString), placeholderImage: UIImage(named: "avatar_default_big"))
        
        layoutIfNeeded()
        UIView.animate(withDuration: 1,
                       delay: 0,
                       usingSpringWithDamping: 0.7,
                       initialSpringVelocity: 0,
                       options: [],
                       animations: {
                        self.bottomConst.constant = self.bounds.height - 200
                        self.layoutIfNeeded()
        }) { (_) in
            
            UIView.animate(withDuration: 1,
                           animations: {
                            self.nickNameLb.alpha = 1
            }, completion: { (_) in
                self.removeFromSuperview()
            })
            
        }
    }
    
}
